package com.learn.jdk;


import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * Copyright: Copyright (c) 2019 Asiainfo
 *
 * @ClassName: com.learn.jdk.composeTest
 * @Description: 该类的功能描述
 * @version: v1.0.0
 * @author: lipan
 * @date: 2019/10/20 17:53
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2019/10/20      lipan          v1.0.0               修改原因
 */

public class composeTest {




    public static void main(String[] args) {

        System.out.println(method1(4, value -> value * value, value -> value * 2,value->value+10));

        System.out.println(method2(4, val -> val * val, val -> val * 2,val->val+10));

        System.out.println(method3(4, val -> val * val, val -> val * 2,val->val+10));

        System.out.println(method4(4, val -> val * val, val -> val * 2,val->val+10));

        System.out.println(method5(10, 12, (a, b) -> a + b));


        System.out.println(method6(5, 10, (a, b) -> a + b, v -> v * v));


    }


    public static int  method1(int value,Function<Integer,Integer> fun1,Function<Integer,Integer> fun2,Function<Integer,Integer> fun3){

        return fun1.compose(fun2).compose(fun3).apply(value);//先执行fun3、再执行fun2、再执行fun1
    }

    public static int  method2(int value,Function<Integer,Integer> fun1,Function<Integer,Integer> fun2,Function<Integer,Integer> fun3){

        return fun1.andThen(fun2).andThen(fun3).apply(value);//先执行fun1、fun2、fun3。
    }


    public static int  method3(int value,Function<Integer,Integer> fun1,Function<Integer,Integer> fun2,Function<Integer,Integer> fun3){

        return fun1.compose(fun2).andThen(fun3).apply(value);//先执行fun2、再fun1、最后fun3
    }


    public static int  method4(int value,Function<Integer,Integer> fun1,Function<Integer,Integer> fun2,Function<Integer,Integer> fun3){

        return fun1.andThen(fun2).compose(fun3).apply(value);//先执行fun3、再执行fun1、再执行fun2
    }


    //biFunction
    public static int  method5(int a, int b, BiFunction<Integer,Integer,Integer> fun){

         return fun.apply(a,b);
     }


    public static int  method6(int a, int b, BiFunction<Integer,Integer,Integer> fun1,Function<Integer,Integer> fun2 ){

        return   fun1.andThen(fun2).apply(a,b);
    }





}
